package util;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
/**
 * XML工具类
 * 
 * @author gongkai
 *
 */
public class XMLUtils {
	public static Document getElement(String xmlPath){
		 // 1、创建工厂
		DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

		// 2、得到dom解析器
		DocumentBuilder db = null;
		try {
			db = dbf.newDocumentBuilder();
		} catch (ParserConfigurationException e) {
			e.printStackTrace();
			return null;
		}

		// 3、解析xml文档，得到代表文档的document
		try {
			return db.parse("src/myxml.xml");
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
}
